﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public abstract class CompositeNodeHandler : BaseNodeHandler
{

    public override BehaviorNodeState ExcuteNode(BehaviorEntity entity,NodeData node)
    {
        if (node.CurNodeState == BehaviorNodeState.Success || node.CurNodeState == BehaviorNodeState.Failure)
        {
            ResetNode(node);
        }
       return HandleComposite(entity,(MultiBranchNodeData)node);
    }

    public abstract BehaviorNodeState HandleComposite(BehaviorEntity entity, MultiBranchNodeData node);

    public override void ResetNode(NodeData node)
    {
        node.CurNodeState = BehaviorNodeState.Running;
        MultiBranchNodeData data = (MultiBranchNodeData)node;
        data.CurIndex = 0;
        for (int i = 0; i < data.ChildNodes.Count; i++)
        {
            GetChildNodeHandler(data.ChildNodes[i].CurNodeType).ResetNode(data.ChildNodes[i]);
        }
    }


}